<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时不可以修改本文件，影响升级覆盖
 */

class Wenda extends \Phpcmf\Home\Module
{

	public function index() {
		//get 参数
		$id = (int)\Phpcmf\Service::L('input')->get('id');
		$wenda_data = \Phpcmf\Service::M()->db->table('1_wenda')->where('id', $id)->where('fstatus', 1)->get()->getRowArray();
		$wenda_data_0 = \Phpcmf\Service::M()->db->table('1_wenda_data_0')->where('id', $id)->get()->getRowArray();
		// 免费试读
		$shidu_data = \Phpcmf\Service::M()->db->table('1_wenda')->where('id', $id)->countAllResults();
		//已读统计
		$yidu_data = \Phpcmf\Service::M()->db->table('1_wenda_yidu')->where('id', $id)->countAllResults();
		// 导航
		$daohang_data = \Phpcmf\Service::M()->db->table('1_wenda_category')->where('id', $wenda_data['catid'])->get()->getRowArray();
		// 加入圈子
		//$jiaquan_data = \Phpcmf\Service::M()->table('1_quan_jiaquan')->where('quanid', $id)->getAll();
		// 循环 $jiaquan_data ， 把 $jiaquan_data['uid'] 替换为 用户名
		$touxiang = dr_avatar($wenda_data['uid']);
		/*foreach($jiaquan_data as $key => $val){
			//判断 小于20 之内的数据
			if($key < 20){
				$touxiang[$key] = dr_avatar($val['uid']);
				
			}
		}*/
		$user = dr_member_info($wenda_data['uid']);
				$userweixin = \Phpcmf\Service::M()->db->table('member_oauth')->where('uid', $wenda_data['uid'])->get()->getRowArray();
				if($userweixin){
					$mingcheng = $userweixin['nickname'];
				} else if($user['name']) {
					$mingcheng = $user['name'];
				} else {
					$mingcheng = $user['username'];
				}
		// 内容
		$list_data[] = [
			'id' => $wenda_data['id'],
			'uid' => $wenda_data['uid'],
			'mingcheng' => $mingcheng,
			'tubiao' => dr_thumb($wenda_data['thumb'], 240, 320, 0, 'crop'),
			'touxiang' => $touxiang,
			'title' => $wenda_data['title'],
			'jianjie' => dr_strcut(dr_clearhtml($wenda_data['description']), 100),
			'neirong_data' => htmlspecialchars_decode($wenda_data_0['content']),
			'fabushijian' => dr_date($wenda_data['inputtime'], 'Y-m-d H:i:s'),
			'kaifangfabu' => $wenda_data['kaifangfabu'],
			'fstatus' => $wenda_data['fstatus'],
			'jiage' => $wenda_data['jiage'],
			'tongji_ke' => $wenda_data['kecheng_total'],
			'lanmu_name' => $daohang_data['name'],
			'lanmu_id' => $wenda_data['catid'],
			'shidu' => $shidu_data,
			'yidu' => $yidu_data,
			'hits' => $wenda_data['hits'],
			'shangjin' => $wenda_data['shangjin'],
			'zhuangtai' => $wenda_data['zhuangtai'],
		];

		$this->_json('1', '读取成功', $list_data);
	}

}
